/*
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates.
 * All rights reserved. Use is subject to license terms.
 *
 * This file is available and licensed under the following license:
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  - Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the distribution.
 *  - Neither the name of Oracle nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.onlyxiahui.common;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.scene.control.Tooltip;
import com.sun.javafx.css.StyleManager;

public class ButtonSample extends Application {

	private static final Color color = Color.web("#464646");
	Button button3 = new Button("Decline");
	DropShadow shadow = new DropShadow();
	Label label = new Label();

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) {
		Scene scene = new Scene(new Group());
		stage.setTitle("Button Sample");
		stage.setWidth(300);
		stage.setHeight(190);
		//scene.getStylesheets().add("com/java/font/font.css");

		label.setFont(Font.font("Times New Roman", 22));
		label.setTextFill(color);

		VBox vbox = new VBox();
		vbox.setLayoutX(20);
		vbox.setLayoutY(20);
		HBox hbox1 = new HBox();
		HBox hbox2 = new HBox();

		Button button1 = new Button("\uf26E \uF0BE1 😁");
		// button1.setFont(Font.font("FontAwesome"));
		Tooltip minTooltip = new Tooltip("最小化");
		button1.setTooltip(minTooltip);

		button1.getStyleClass().add("button1");
		button1.getStyleClass().add("font-icon");

		button1.setOnAction((ActionEvent e) -> {
			label.setText("Accepted");
		});

		Button button2 = new Button("\uf2B9");
		button2.setOnAction((ActionEvent e) -> {
			label.setText("Accepted");
		});

		button3.setOnAction((ActionEvent e) -> {
			label.setText("Declined");
		});

		button3.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			button3.setEffect(shadow);
		});

		button3.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			button3.setEffect(null);
		});

		hbox1.getChildren().add(button2);
		hbox1.getChildren().add(button3);
		hbox1.getChildren().add(label);
		hbox1.setSpacing(10);
		hbox1.setAlignment(Pos.BOTTOM_CENTER);

		Button button4 = new Button();
		button4.setOnAction((ActionEvent e) -> {
			label.setText("Accepted");
		});

		Button button5 = new Button();
		button5.setOnAction((ActionEvent e) -> {
			label.setText("Declined");
		});

		hbox2.getChildren().add(button4);
		hbox2.getChildren().add(button5);
		hbox2.setSpacing(25);

		vbox.getChildren().add(button1);
		vbox.getChildren().add(hbox1);
		vbox.getChildren().add(hbox2);
		vbox.setSpacing(10);
		((Group) scene.getRoot()).getChildren().add(vbox);

		stage.setScene(scene);
		stage.show();
		// 此方式需要stage.show();执行后再执行才起效果
		StyleManager.getInstance().addUserAgentStylesheet(ButtonSample.class.getResource("/com/only/common/css/Only.css").toString());
	}
}